﻿using lDal;

namespace DAL
{
    public class BaseDal<T> : lBaseDal<T> where T : class
    {
        public BaseDal(MyDbContext db)
        {
            Db = db;
        }

        public MyDbContext Db { get; }

        public Task<int> AddAsync(T T)
        {
           Db.Set<T>().AddAsync(T);
           return Db.SaveChangesAsync();
        }

        public Task<int> AddRangeAsync(List<T> list)
        {
            Db.Set<T>().AddRangeAsync(list);
            return Db.SaveChangesAsync();
        }

        public IQueryable<T> GetList()
        {
            return Db.Set<T>();
        }

        public Task<int> RemoveAsync(T T)
        {
            Db.Set<T>().Remove(T);
            return Db.SaveChangesAsync();
        }

        public Task<int> RemoveRangeAsync(List<T> list)
        {
           Db.Set<T>().RemoveRange(list);
            return Db.SaveChangesAsync();
        }

        public Task<int> UpdateAsync(T T)
        {
            Db.Set<T>().Update(T);
            return Db.SaveChangesAsync();
        }

        public Task<int> UpdateRangeAsync(List<T> list)
        {
            Db.Set<T>().UpdateRange(list);
            return Db.SaveChangesAsync();
        }
    }
}
